static char *distopt = NULL;
static char *arcfileopt = NULL;
static char *exclopt = NULL;
+static char *ptsopt = NULL;
typedef struct {
double distance;
{"distance", &distopt, "Maximum distance from arc",
ARGTYPE_FLOAT | ARGTYPE_REQUIRED},
{"exclude", &exclopt, "Exclude points close to the arc", ARGTYPE_BOOL},
+ {"points", &ptsopt, "Use distance from vertices not lines",
+ ARGTYPE_BOOL},
{0, 0, 0, 0}
};
if ( argsfound != 2 && strspn(line, " \t\n") < strlen(line)) {
warning(MYNAME ": Warning: Arc file contains unusable vertex on line %d.\n", fileline );
}
- else if ( lat1 != BADVAL && lon1 != BADVAL &&
- lat2 != BADVAL && lon2 != BADVAL ) {
+ else if ( lat2 != BADVAL && lon2 != BADVAL &&
+ (ptsopt || (lat1 != BADVAL && lon1 != BADVAL ))) {
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
waypointp = (waypoint *)elem;
- dist = linedist(lat1, lon1, lat2, lon2,
+ if ( ptsopt ) {
+ dist = gcdist( lat2*M_PI/180.0, lon2*M_PI/180.0,
+ waypointp->latitude*M_PI/180.0,
+ waypointp->longitude*M_PI/180.0 );
+ }
+ else {
+ dist = linedist(lat1, lon1, lat2, lon2,
waypointp->latitude,
waypointp->longitude );
+ }
/* convert radians to float point statute miles */
- dist = (((dist * 180.0 * 60.0) / M_PI) * 1.1516);
+ dist = tomiles(dist);
if ( waypointp->extra_data ) {
ed = (extra_data *) waypointp->extra_data;
return (x1*x2+y1*y2+z1*z2);
}
+/*
+ * Note: this conversion to miles uses the WGS84 value for the radius of
+ * the earth at the equator.
+ * (radius in meters)*(100cm/m) -> (radius in cm)
+ * (radius in cm) / (2.54 cm/in) -> (radius in in)
+ * (radius in in) / (12 in/ft) -> (radius in ft)
+ * (radius in ft) / (5280 ft/mi) -> (radius in mi)
+ * If the compiler is half-decent, it'll do all the math for us at compile
+ * time, so why not leave the expression human-readable?
+ */
+
+double tomiles( double rads ) {
+ const double radmiles = 6378137.0*100.0/2.54/12.0/5280.0;
+ return (rads*radmiles);
+}
+
double gcdist( double lat1, double lon1, double lat2, double lon2 ) {
return acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));
}
comp[i]->longitude);
/* convert radians to integer feet */
- dist = (int)((((dist * 180.0 * 60.0) / M_PI) * 1.1516) * 5280.0);
+ dist = (int)(5280*tomiles(dist));
if (dist <= pos_dist) {
switch (qtype) {
home_pos->longitude);
/* convert radians to float point statute miles */
- dist = (((dist * 180.0 * 60.0) / M_PI) * 1.1516);
+ dist = tomiles(dist);
if ((dist >= pos_dist) == (exclopt == NULL)) {
waypt_del(waypointp);